<template>
  <!--教育经历-->
  <view>
    <myHead
      :title="title"
      :right="true"
      text_right="保存"
      @clickRight="clickRight"
    ></myHead>
    <view class="conten">
      <u-picker
        :show="showeEducation"
        closeOnClickOverlay
        @cancel="showeEducation = false"
        @close="showeEducation = false"
        keyName="text"
        :columns="education"
        @confirm="educationchange"
      >
      </u-picker>
      <view class="li-box fl-lr-c radius16" @click="showeEducation = true">
        <view class="name">最高学历</view>
        <view class="fl-t">
          <view class="content">
            {{ lsit2text || "请选择" }}
          </view>
          <u-icon name="arrow-right"></u-icon>
        </view>
      </view>

      <view class="content2" v-if="value">
        <view class="li-box fl-lr-c" v-if="!(value == '2' || value == '1')">
          <view class="name">学校名称</view>
          <view>
            <input
              v-model="SchoolName"
              placeholder-class="input_pal"
              type="text"
              placeholder="请输入"
            />
          </view>
        </view>
        <view class="li-box fl-lr-c" v-if="!(value == '2' || value == '1')">
          <view class="name">所属专业</view>
          <view>
            <input
              placeholder-class="input_pal"
              type="text"
              v-model="Major"
              placeholder="请输入"
            />
          </view>
        </view>
        <view class="li-box fl-lr-c" v-if="!(value == '2' || value == '1')">
          <view class="name">是否统招</view>
          <view class="fl-t">
            <u-radio-group v-model="EduType" placement="row">
              <u-radio
                :customStyle="{ marginLeft: '35rpx' }"
                v-for="(item, index) in boolean"
                :key="index"
                :label="item.name"
                :name="item.value"
                @change="fnRadio1"
              >
              </u-radio>
            </u-radio-group>
          </view>
        </view>
        <view class="li-box fl-lr-c" v-if="value >= 5">
          <view class="name">学位证书</view>
          <view class="fl-t">
            <u-radio-group v-model="Certificate" placement="row">
              <u-radio
                :customStyle="{ marginLeft: '35rpx' }"
                v-for="(item, index) in booleanCertificate"
                :key="index"
                :label="item.name"
                :name="item.value"
                @change="fnRadio2"
              >
              </u-radio>
            </u-radio-group>
          </view>
        </view>
        <u-datetime-picker
          v-if="show1"
          :show="show1"
          mode="year-month"
          title="请选择入学时间"
          closeOnClickOverlay
          @close="show1 = false"
          :minDate="minDate"
          :maxDate="maxDate"
          @cancel="show1 = false"
          @confirm="changeDirthDate"
          v-model="value1"
        ></u-datetime-picker>
        <u-datetime-picker
          v-if="show2"
          :show="show2"
          mode="year-month"
          title="请选择毕业时间"
          closeOnClickOverlay
          @close="show2 = false"
          :minDate="minDate2"
          :maxDate="maxDate2"
          @cancel="show2 = false"
          v-model="value2"
          @confirm="changeDirthDate"
        ></u-datetime-picker>
        <view class="li-box fl-lr-c" v-if="!(value == '2' || value == '1')">
          <view class="name">在校时间</view>
          <view class="fl-t">
            <view class="content fl-t">
              <text @click="linJob(1)">
                <text v-if="startTime">{{ startTime | formatDateYM }}</text>
                <text v-else>入学时间</text>
              </text>
              <view class="connect">-</view
              ><text @click="linJob(2)">
                <text v-if="endTime">{{ endTime | formatDateYM }}</text>
                <text v-else>毕业时间</text>
              </text>
            </view>
            <u-icon name="arrow-right"></u-icon>
          </view>
        </view>
      </view>
      <bottomBut @bottomBut="bottomBut" v-if="type == 2"></bottomBut>
    </view>
  </view>
</template>

<script>
import myHead from "@/pages/component/baseHead.vue";
import bottomBut from "@/pages/component/bottomBut.vue";
import {
  atPresentTime,
  specifyBeforeVX,
  atPresentTimeX,
  specifyAfterVX,
  TimeString,
} from "@/utils/Time";
export default {
  data() {
    return {
      type: 1,
      title: "教育经历",
      show1: false,
      show2: false,
      education: [],
      showeEducation: false,
      boolean: [
        {
          //统招 类型 0统招 1非统招
          name: "是",
          value: 0,
        },
        {
          name: "否",
          value: 1,
        },
      ],
      booleanCertificate: [
        {
          //学位证书 类型 0统招 1非统招
          name: "有",
          value: 1,
        },
        {
          name: "无",
          value: 0,
        },
      ],
      value: "",
      SchoolName: "",
      Major: "", //专业
      EduType: "", //统招
      startTime: "",
      endTime: "",
      dateType: 1,
      year: "",
      // 当前id
      Id: 0,
      // 父id
      fuid: 0,
      Certificate: "", //学位证书
      maxDate: "", //最大入学时间
      minDate: "", //最小入学时间
      maxDate2: "", //最大毕业时间
      value1: "",
      value2: "",
    };
  },
  //子组件
  components: {
    myHead,
    bottomBut,
  },
  onLoad(o) {
    this.maxDate = atPresentTime();
    this.maxDate2 = specifyAfterVX(this.maxDate, 10);
    this.minDate = atPresentTimeX(60);
    let nowDate = new Date();
    this.year = nowDate.getFullYear();
    this.type = o.type;
    this.fuid = o.fuid;
    if (this.type == 2) {
      let data = JSON.parse(o.data);
      console.log(data);
      this.Id = data.Id;
      this.value = data.EduDegree;
      this.SchoolName = data.SchoolName;
      this.Major = data.Major;
      this.EduType = data.EduType;
      this.startTime = data.StartDate.split(" ")[0];
      this.endTime = data.EndDate.split(" ")[0];
    }
  },
  created() {
    this.xialadata();
  },
  computed: {
    lsit2text() {
      let arr = [];
      if (this.education.length > 0) {
        arr = this.education[0].filter((res) => {
          return this.value == res.value;
        });
      }
      if (arr.length == 0) {
        return "";
      } else {
        return arr[0].text || " ";
      }
    },
    minDate2() {
      if (this.startTime) {
        return specifyBeforeVX(this.startTime, 0);
      } else {
        return this.minDate;
      }
    },
  },
  // 计算方法
  methods: {
    xialadata() {
      this.$http.dic.DataSelector(385800548573317).then((res) => {
        if (res.Success) {
          // console.log(res.Result);
          this.education = this.xialist(res.Result);
          // console.log(this.education);
        }
      });
    },
    xialist(arr) {
      let drr = [];
      arr.forEach((res) => {
        let obj = {
          text: res.FullName,
          value: res.EnCode,
        };
        drr.push(obj);
      });
      return [drr];
    },
    bottomBut() {
      let that = this;
      console.log("删除");
      uni.showModal({
        title: "删除提示",
        content: "确认要删除这条数据",
        success: function (res) {
          if (res.confirm) {
            let data = {
              Id: that.Id,
            };
            that.$http.huirc.resumeeducationexpdel(data).then((res) => {
              if (res.Success) {
                that.$util.toast("删除成功");
                setTimeout(() => {
                  uni.navigateBack();
                }, 1000);
              }
            });
          }
        },
      });
    },
    linJob(type) {
      // console.log(type);
      this.dateType = type;
      if (type == 1) {
        this.value1 = this.startTime
          ? this.startTime
          : TimeString(this.maxDate);
        this.show1 = true;
      } else {
        this.value2 = this.endTime ? this.endTime : TimeString(this.maxDate2);
        this.show2 = true;
      }
    },
    init(str) {
      //查找id
      this.education.forEach((item) => {
        if (item.text == str) {
          this.id = item.value;
        }
      });
    },
    changeDirthDate(e) {
      const timeFormat = uni.$u.timeFormat;
      let ds = timeFormat(e.value, "yyyy-mm-dd");
      if (this.dateType == 1) {
        //开始
        if (this.endTime) {
          if (ds > this.endTime) {
            this.$util.toast("入学时间不能高于毕业时间");
            return;
          }
        }
        this.startTime = ds;
      } else {
        if (this.startTime) {
          if (ds < this.startTime) {
            this.$util.toast("毕业时间不能低于入学时间");
            return;
          }
        }
        this.endTime = ds;
      }
      this.show1 = false;
      this.show2 = false;
    },
    fnRadio1(e) {
      // console.log(e);
      this.EduType = e;
    },
    fnRadio2(e) {
      // console.log(e, typeof e);''
      this.Certificate = e;
    },
    clickRight() {
      //校验
      if (!this.value) {
        this.$util.toast("请选择学历");
        return;
      }
      if (!this.SchoolName.length && this.value > 2) {
        this.$util.toast("请输入学校名称");
        return;
      }
      if (!this.Major.length && this.value > 2) {
        this.$util.toast("请输入所属专业");
        return;
      }
      if (this.value >= 3 && !(this.EduType == "0" || this.EduType == "1")) {
        // debugger
        console.log(this.value, this.EduType);
        this.$util.toast("请选择是否统招");
        return;
      }
      // (this.value >= 5) &&  !(this.Certificate == 0 || this.Certificate == 1
      if (
        this.value >= 5 &&
        !(this.Certificate == "0" || this.Certificate == "1")
      ) {
        console.log(this.value, this.Certificate);
        this.$util.toast("请选择是否有学历证书");
        return;
      }
      if (!this.startTime.length && this.value > 2) {
        this.$util.toast("请选择入校时间");
        return;
      }
      if (!this.endTime.length && this.value > 2) {
        this.$util.toast("请选择毕业时间");
        return;
      }

      if (this.type == 2) {
        //编辑修改
        let data = {
          Id: this.Id,
          ResumeId: this.fuid,
          SchoolId: 0,
          SchoolName: this.SchoolName,
          Major: this.Major,
          EduDegree: this.value, //教育程度
          EduType: this.EduType, // 0统招 1非统招
          StartDate: this.startTime,
          EndDate: this.endTime,
          EducationDesc: "",
          SortCode: 0,
          Academic: this.Certificate, //学位证书
        };
        if (this.value > 2 && this.Major == "") {
          this.$util.toast("请输入所学专业");
        } else {
          this.$http.huirc.resumeeducationexpup(data).then((res) => {
            if (res.Success) {
              this.$util.toast("保存成功");
              setTimeout(() => {
                uni.navigateBack();
              }, 1000);
            }
          });
        }
      } else {
        let data = {
          ResumeId: this.fuid,
          SchoolId: 0,
          SchoolName: this.SchoolName,
          Major: this.Major,
          EduDegree: this.value, //教育程度
          EduType: this.EduType, // 0统招 1非统招
          StartDate: this.startTime,
          EndDate: this.endTime,
          EducationDesc: "",
          SortCode: 0,
          Academic: this.Certificate, //学位证书
        };
        if (this.value > 2 && this.Major == "") {
          this.$util.toast("请输入所学专业");
        } else {
          this.$http.huirc.resumeeducationexpcr(data).then((res) => {
            if (res.Success) {
              this.$util.toast("保存成功");
              setTimeout(() => {
                uni.navigateBack();
              }, 1000);
            }
          });
        }
      }
    },
    educationchange(e) {
      // console.log(e)
      this.value = e.value[0].value;
      this.showeEducation = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.li-box {
  .name {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: bold;
    color: #000000;
    flex-shrink: 0;
  }

  .logo {
    width: 106rpx;
    height: 106rpx;
    border-radius: 50%;
  }

  .input_pal,
  input,
  .content {
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #999999;
    text-align: end;

    .connect {
      padding: 0 20rpx;
      color: #000;
      font-size: 32rpx;
    }
  }

  .radio-box {
    margin-left: 50rpx;

    .radio-text {
      font-size: 30rpx;
      font-family: PingFang SC;
      font-weight: 500;
      color: #999999;
      padding-left: 20rpx;
    }
  }
}
</style>
